package ObserverMode.InitialEdition.observer.impl;

import ObserverMode.InitialEdition.observer.DisplayElement;
import ObserverMode.InitialEdition.observer.Observer;
import ObserverMode.InitialEdition.subject.Subject;

/**
 * 目前状态公告板
 * 实现了Observer接口，所以可以从WeatherData对象中获得改变
 * @Author Li Cheng
 * @Date 2021/8/12 22:24
 * @Version 1.0
 */
public class CurrentConditionDisplay implements Observer , DisplayElement {

    private float temperature;
    private float humidity;
    private Subject weatherData;

    public CurrentConditionDisplay(Subject weatherData) {
        this.weatherData = weatherData;
        weatherData.registerObserver(this);
    }

    @Override
    public void display() {
        System.out.println("Current conditions: " + temperature + " F degrees and "+ humidity + "% humidity");
    }

    @Override
    public void update(float temp, float humidity, float pressure) {
        this.temperature = temp;
        this.humidity = humidity;
        display();
    }
}
